package org.jeecg.modules.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.system.entity.ZkWorkBook;
import org.jeecg.modules.system.entity.ZkWorkBookData;
import org.jeecg.modules.system.service.IZkWorkBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 作业指导书
 * @Author: jeecg-boot
 * @Date:   2024-07-01
 * @Version: V1.0
 */
@Api(tags="作业指导书")
@RestController
@RequestMapping("/zkWorkBook/zkWorkBook")
@Slf4j
public class ZkWorkBookController extends JeecgController<ZkWorkBook, IZkWorkBookService> {
	@Autowired
	private IZkWorkBookService zkWorkBookService;

	/**
	 * 分页列表查询
	 *
	 * @param zkWorkBookData
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "作业指导书-分页列表查询")
	@ApiOperation(value = "作业指导书-分页列表查询", notes = "作业指导书-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<ZkWorkBookData>> queryPageList(ZkWorkBookData zkWorkBookData,
												   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
												   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
												   HttpServletRequest req) {
		Result<IPage<ZkWorkBookData>> result = new Result<IPage<ZkWorkBookData>>();
		Page<ZkWorkBookData> page = new Page<ZkWorkBookData>(pageNo, pageSize);

		IPage<ZkWorkBookData> pageList = zkWorkBookService.queryZkWorkBookData(page, zkWorkBookData);
		return Result.OK(pageList);
	}

	/**
	 * 添加
	 *
	 * @param zkWorkBook
	 * @return
	 */
	@AutoLog(value = "作业指导书-添加")
	@ApiOperation(value = "作业指导书-添加", notes = "作业指导书-添加")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody ZkWorkBook zkWorkBook) {
		zkWorkBookService.save(zkWorkBook);
		return Result.OK("添加成功！");
	}

	/**
	 * 编辑
	 *
	 * @param zkWorkBook
	 * @return
	 */
	@AutoLog(value = "作业指导书-编辑")
	@ApiOperation(value = "作业指导书-编辑", notes = "作业指导书-编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
	public Result<String> edit(@RequestBody ZkWorkBook zkWorkBook) {
		zkWorkBookService.updateById(zkWorkBook);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "作业指导书-通过id删除")
	@ApiOperation(value = "作业指导书-通过id删除", notes = "作业指导书-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
		zkWorkBookService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "作业指导书-批量删除")
	@ApiOperation(value = "作业指导书-批量删除", notes = "作业指导书-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
		this.zkWorkBookService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "作业指导书-通过id查询")
	@ApiOperation(value = "作业指导书-通过id查询", notes = "作业指导书-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<ZkWorkBook> queryById(@RequestParam(name = "id", required = true) String id) {
		ZkWorkBook zkWorkBook = zkWorkBookService.getById(id);
		if (zkWorkBook == null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(zkWorkBook);
	}

	/**
	 * 导出excel
	 *
	 * @param request
	 * @param zkWorkBook
	 */
	@RequiresPermissions("zkWorkBook:zk_work_book:exportXls")
	@RequestMapping(value = "/exportXls")
	public ModelAndView exportXls(HttpServletRequest request, ZkWorkBook zkWorkBook) {
		return super.exportXls(request, zkWorkBook, ZkWorkBook.class, "作业指导书");
	}

	/**
	 * 通过excel导入数据
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequiresPermissions("zkWorkBook:zk_work_book:importExcel")
	@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
	public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		return super.importExcel(request, response, ZkWorkBook.class);
	}

	/**
	 * 查询全部作业指导书
	 */
	@IgnoreAuth
	@AutoLog(value = "查询全部作业指导书")
	@ApiOperation(value = "查询全部作业指导书", notes = "查询全部作业指导书")
	@GetMapping(value = "/queryZkWorkBook")
	public Result<?> queryZkWorkBook(String level,String customName,String proces,String productNumber,String productName) {

	 List<ZkWorkBookData> list=this.zkWorkBookService.queryZkWorkBook(level,customName,proces,productNumber,productName);
	 return Result.ok(list);
	}

	/**
	 * 查询客户名称作为下拉选项
	 */
	@IgnoreAuth
	@AutoLog(value = "查询客户名称作为下拉选项")
	@ApiOperation(value = "查询客户名称作为下拉选项", notes = "查询客户名称作为下拉选项")
	@GetMapping(value = "/queryCustomName")
	public Result<?> queryCustomName() {

		List<String> customName=this.zkWorkBookService.queryCustomName();
		return Result.ok(customName);
	}

	/**
	 * 查询工序作为下拉选项
	 */
	@IgnoreAuth
	@AutoLog(value = "查询工序作为下拉选项")
	@ApiOperation(value = "查询工序作为下拉选项", notes = "查询工序作为下拉选项")
	@GetMapping(value = "/quryProces")
	public Result<?> quryProces() {

		List<String> proces=this.zkWorkBookService.quryProces();
		return Result.ok(proces);
	}

	/**
	 * 查询产品编号下拉选项
	 */
	@IgnoreAuth
	@AutoLog(value = "查询产品编号下拉选项")
	@ApiOperation(value = "查询产品编号下拉选项", notes = "查询产品编号下拉选项")
	@GetMapping(value = "/queryProductNumber")
	public Result<?> queryProductNumber() {

		List<String> productNumber=this.zkWorkBookService.queryProductNumber();
		return Result.ok(productNumber);
	}

	/**
	 * 查询产品名称下拉选项
	 */
	@IgnoreAuth
	@AutoLog(value = "查询产品名称下拉选项")
	@ApiOperation(value = "查询产品名称下拉选项", notes = "查询产品名称下拉选项")
	@GetMapping(value = "/queryProductName")
	public Result<?> queryProductName() {

		List<String> productName=this.zkWorkBookService.queryProductName();
		return Result.ok(productName);
	}

}
